/*     */ package nc.ui.bd.cust.baseinfo.action;
/*     */ 
/*     */ import java.awt.event.ActionEvent;

/*     */ import nc.bs.framework.common.NCLocator;
/*     */ import nc.bs.logging.Logger;
/*     */ import nc.itf.bd.bankacc.base.IBankAccBaseInfoQueryService;
import nc.itf.bd.cust.baseinfo.ICustBaseInfoService;
/*     */ import nc.itf.uap.IUAPQueryBS;
/*     */ import nc.ui.pub.beans.MessageDialog;
/*     */ import nc.ui.uif2.UIState;
/*     */ import nc.ui.uif2.actions.RefreshSingleAction;
/*     */ import nc.ui.uif2.actions.SaveAction;
/*     */ import nc.ui.uif2.editor.IEditor;
/*     */ import nc.ui.uif2.model.AbstractAppModel;
/*     */ import nc.vo.bd.cust.CustomerVO;
/*     */ import nc.vo.ml.AbstractNCLangRes;
/*     */ import nc.vo.ml.NCLangRes4VoTransl;
/*     */ import nc.vo.org.OrgVO;
/*     */ import nc.vo.pub.BusinessException;
/*     */ import nc.vo.uif2.LoginContext;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class CustomerSaveAction
/*     */   extends SaveAction
/*     */ {
/*     */   public CustomerSaveAction() {}
/*     */   
/*  31 */   private IUAPQueryBS queryService = null;
/*     */   
/*  33 */   private IBankAccBaseInfoQueryService bankaccqueryservice = null;
/*     */   
/*  35 */   private RefreshSingleAction refreshAction = null;
/*     */   
/*     */   public RefreshSingleAction getRefreshAction() {
/*  38 */     return this.refreshAction;
/*     */   }
/*     */   
/*     */   public void setRefreshAction(RefreshSingleAction refreshAction) {
/*  42 */     this.refreshAction = refreshAction;
/*     */   }
/*     */   
/*     */   private static final long serialVersionUID = 1L;
/*     */   public void doAction(ActionEvent e)
/*     */     throws Exception
/*     */   {
/*  49 */     Object value = getEditor().getValue();
/*  50 */     validate(value);
/*  51 */     if (getModel().getUiState() == UIState.ADD) {
/*  52 */       doAddSave(value);
/*     */     }
/*  54 */     else if (getModel().getUiState() == UIState.EDIT) {
/*  55 */       doEditSave(value);
/*     */     }
/*     */     
/*  58 */     showSuccessInfo();
/*     */   }
/*     */   
/*     */   protected void doEditSave(Object value) throws Exception
/*     */   {
/*  63 */     CustomerVO vo = (CustomerVO)value;
/*  64 */     String pk_customer = vo.getPk_customer();
/*  65 */     CustomerVO oldvo = (CustomerVO)getQueryService().retrieveByPK(CustomerVO.class, pk_customer);
/*  66 */     checkOldVONotNull(vo, oldvo);
/*     */     
/*  68 */     if ((vo.getCustprop() != null) && (oldvo.getCustprop() != null) && (vo.getCustprop().intValue() == 1) && (oldvo.getCustprop().intValue() == 0))
/*     */     {
/*  70 */       String pk_org = vo.getPk_financeorg();
/*  71 */       OrgVO orgvo = (OrgVO)getQueryService().retrieveByPK(OrgVO.class, pk_org);
/*  72 */       String[] repeateaccnums = getBankAccBaseInfoQueryService().queryBankaccForCustSupUpdate(pk_org, vo.getPk_customer());
/*     */       
/*     */ 
/*  75 */       if ((repeateaccnums != null) && (repeateaccnums.length > 0)) {
/*  76 */         StringBuffer accnumstr = new StringBuffer();
/*  77 */         for (int i = 0; i < repeateaccnums.length; i++) {
/*  78 */           accnumstr.append(repeateaccnums[i]);
/*  79 */           if (i != repeateaccnums.length - 1)
/*  80 */             accnumstr.append(",");
/*     */         }
/*  82 */         int result = MessageDialog.showOkCancelDlg(getModel().getContext().getEntranceUI(), NCLangRes4VoTransl.getNCLangRes().getStrByID("10140cub", "110140cub0043"), NCLangRes4VoTransl.getNCLangRes().getStrByID("10140cub", "110140cub0044", null, new String[] { orgvo.getName(), accnumstr.toString(), accnumstr.toString(), orgvo.getName(), accnumstr.toString() }));
/*     */         
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 107 */         if (result != 1) {
/* 108 */           return;
/*     */         }
/*     */       }
/*     */     }
/*     */     
/* 113 */     super.doEditSave(value);
/*     */   }
/*     */   
/*     */   private void checkOldVONotNull(CustomerVO vo, CustomerVO oldvo) throws BusinessException
/*     */   {
/* 118 */     if (oldvo == null) {
/* 119 */       String msg = String.format("Customer code:%s name:%s has been deleted. Please Refresh the UI.", new Object[] { vo.getCode(), vo.getName() });
/*     */       
/*     */ 
/* 122 */       Logger.error(msg);
/* 123 */       throw new BusinessException(msg);
/*     */     }
/*     */   }
/*     */   
/*     */   private IUAPQueryBS getQueryService() {
/* 128 */     if (this.queryService == null)
/* 129 */       this.queryService = ((IUAPQueryBS)NCLocator.getInstance().lookup(IUAPQueryBS.class));
/* 130 */     return this.queryService;
/*     */   }
/*     */   
/*     */   private IBankAccBaseInfoQueryService getBankAccBaseInfoQueryService() {
/* 134 */     if (this.bankaccqueryservice == null)
/* 135 */       this.bankaccqueryservice = ((IBankAccBaseInfoQueryService)NCLocator.getInstance().lookup(IBankAccBaseInfoQueryService.class));
/* 136 */     return this.bankaccqueryservice;
/*     */   }
/*     */ }
